package com.ibeeking.found.upms.api.feign.fallback;

import com.ibeeking.found.upms.api.common.dto.EmployeeDTO;
import com.ibeeking.found.upms.api.common.param.EmployeeParam;
import com.ibeeking.found.upms.api.common.query.EmployeeQuery;
import com.ibeeking.found.upms.api.feign.OrgEmployeeCpFeignClient;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class OrgEmployeeCpFallbackFactory implements FallbackFactory<OrgEmployeeCpFeignClient> {
    @Override
    public OrgEmployeeCpFeignClient create(Throwable throwable) {
        return new OrgEmployeeCpFeignClient() {
            @Override
            public ResponseResult<List<EmployeeDTO>> queryEmployeeList(EmployeeQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询员工信息失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<Boolean> addAndUpdteEmployee(@RequestBody EmployeeParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询员工信息失败。", null);
            }
        };
    }
}
